#include "CLightSceneNode.h"
#include "CSceneManager.h"

ldx::scene::CLightSceneNode::CLightSceneNode(ISceneNode * parent, 
	CSceneManager * mgr, int id, mt::vec4f position, 
	mt::vec3f intensities, float attenuation, 
	float ambientCoefficient, float coneAngle, mt::vec3f coneDirection)
	:ISceneNode(parent, mgr, id, mt::vec3f(position.X,position.Y,position.Z))
{
	setVisible(true);
	LightData = new  render::SLight(position, intensities, attenuation, ambientCoefficient, coneAngle, coneDirection);
}

void ldx::scene::CLightSceneNode::initLight(mt::vec4f position, mt::vec3f intensities, float attenuation, float ambientCoefficient, float coneAngle, mt::vec3f coneDirection)
{
	LightData->set(position, intensities, attenuation,
		ambientCoefficient, coneAngle, coneDirection);
}

void ldx::scene::CLightSceneNode::buildSpotLight( mt::vec4f position, mt::vec3f intensities, float attenuation, float ambientCoefficient)
{
	initLight(mt::vec4f(position.X, position.Y, position.Z, 1.0f), intensities, attenuation, ambientCoefficient, 180.0f);
}

void ldx::scene::CLightSceneNode::buildParalleLight(mt::vec4f position, mt::vec3f intensities, float ambientCoefficient)
{
	initLight(mt::vec4f(position.X, position.Y, position.Z, 0.0f), intensities, 0.0f, ambientCoefficient);
}

void ldx::scene::CLightSceneNode::buildFlashLight(mt::vec4f position, mt::vec3f intensities, float attenuation, float ambientCoefficient, float coneAngle, mt::vec3f coneDirection)
{
	initLight(mt::vec4f(position.X, position.Y, position.Z, 1.0f), 
		intensities, attenuation, ambientCoefficient, coneAngle, coneDirection);
}

const ldx::render::SLight * ldx::scene::CLightSceneNode::getLightData()const
{
	mt::vec3f pos = getAbsolutePosition();
	LightData->position = mt::vec4f(pos.X, pos.Y, pos.Z, LightData->position.W);
	return LightData;
}

void ldx::scene::CLightSceneNode::OnRegisterSceneNode()
{
	SceneManager->registerNodeForRendering(this, ESNRP_LIGHT);

	ISceneNode::OnRegisterSceneNode();
}
